package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DataxEndGroup;
import com.ruoyi.system.service.IDataxEndGroupService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据交换组Controller
 * 
 * @author ruoyi
 * @date 2022-10-04
 */
@Controller
@RequestMapping("/system/group")
public class DataxEndGroupController extends BaseController
{
    private String prefix = "system/group";

    @Autowired
    private IDataxEndGroupService dataxEndGroupService;

    @RequiresPermissions("system:group:view")
    @GetMapping()
    public String group()
    {
        return prefix + "/group";
    }

    /**
     * 查询数据交换组列表
     */
    @RequiresPermissions("system:group:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataxEndGroup dataxEndGroup)
    {
        startPage();
        List<DataxEndGroup> list = dataxEndGroupService.selectDataxEndGroupList(dataxEndGroup);
        return getDataTable(list);
    }

    /**
     * 导出数据交换组列表
     */
    @RequiresPermissions("system:group:export")
    @Log(title = "数据交换组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DataxEndGroup dataxEndGroup)
    {
        List<DataxEndGroup> list = dataxEndGroupService.selectDataxEndGroupList(dataxEndGroup);
        ExcelUtil<DataxEndGroup> util = new ExcelUtil<DataxEndGroup>(DataxEndGroup.class);
        return util.exportExcel(list, "数据交换组数据");
    }

    /**
     * 新增数据交换组
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据交换组
     */
    @RequiresPermissions("system:group:add")
    @Log(title = "数据交换组", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DataxEndGroup dataxEndGroup)
    {
        return toAjax(dataxEndGroupService.insertDataxEndGroup(dataxEndGroup));
    }

    /**
     * 修改数据交换组
     */
    @RequiresPermissions("system:group:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DataxEndGroup dataxEndGroup = dataxEndGroupService.selectDataxEndGroupById(id);
        mmap.put("dataxEndGroup", dataxEndGroup);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据交换组
     */
    @RequiresPermissions("system:group:edit")
    @Log(title = "数据交换组", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DataxEndGroup dataxEndGroup)
    {
        return toAjax(dataxEndGroupService.updateDataxEndGroup(dataxEndGroup));
    }

    /**
     * 删除数据交换组
     */
    @RequiresPermissions("system:group:remove")
    @Log(title = "数据交换组", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dataxEndGroupService.deleteDataxEndGroupByIds(ids));
    }
}
